package com.github.wxiaoqi.security.crm.core.biz;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.crm.core.entity.PersonalBase;
import com.github.wxiaoqi.security.crm.core.entity.PlatformUniqueCustomer;
import com.github.wxiaoqi.security.crm.core.mapper.PersonalBaseMapper;
import com.github.wxiaoqi.security.crm.core.mapper.PlatformUniqueCustomerMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * 平台唯一用户表
 * @author he
 * @date 2018-09-08 14:08:33
 */
@Slf4j
@Service
public class PlatformUniqueCustomerBiz extends BaseBiz<PlatformUniqueCustomerMapper,PlatformUniqueCustomer> {
	
	@Autowired
	private PersonalBaseMapper personalBaseMapper;
	@Autowired
	private PlatformUniqueCustomerMapper platformUniqueCustomerMapper;
	
	/**
	 * 微信小程序火源账户信息查询
	 * @param request
	 * @return
	 */
	public PlatformUniqueCustomer wechatMiniFireSourceInfo(Map<String, Object> request){
		log.info("微信小程序火源账户信息查询.......{}", request);
		PersonalBase personalBase = new PersonalBase();
		personalBase.setPlatformId((String)request.get("platformId"));
		personalBase.setCustomerId((String)request.get("customerId"));
		personalBase.setPersonalId((String)request.get("personalId"));
		PersonalBase selectPersonalBase = personalBaseMapper.selectOne(personalBase);
		if(null != selectPersonalBase && !StringUtils.isEmpty(selectPersonalBase.getIdCard())){
			PlatformUniqueCustomer platformUniqueCustomer = new PlatformUniqueCustomer();
			platformUniqueCustomer.setPlatformId("13608825924956160");//顶级平台编号
			platformUniqueCustomer.setIdCard(selectPersonalBase.getIdCard());
			PlatformUniqueCustomer selectUniqueCustomer = platformUniqueCustomerMapper.selectOne(platformUniqueCustomer);
			log.info("微信小程序火源账户信息查询结束.......");
			return selectUniqueCustomer;
		}else{
			PlatformUniqueCustomer platformUniqueCustomer = new PlatformUniqueCustomer();
			log.info("微信小程序火源账户信息查询结束.......");
			return platformUniqueCustomer;
		}
	}
}